package containers;

import java.awt.Rectangle;
import java.util.concurrent.CopyOnWriteArrayList;

import util.CardValues;

import casino.Casino;
import casino.GameCard;
import casino.Player;

public abstract class CardContainer extends Rectangle{
	public CopyOnWriteArrayList<GameCard> cards = new CopyOnWriteArrayList<GameCard>();
	public Casino casino;
	public Player owner;
	
	public CardContainer(Casino n){
		super(0,0,CardValues.width,CardValues.height);
		casino = n;
	}
	public CardContainer(Casino n, Player o, int x, int y, int w, int h){
		super(x,y,w,h);
		casino = n;
		owner = o;
	}
	
	public CardContainer(Casino n, Player o, int x, int y, int w, int h, CopyOnWriteArrayList<GameCard> c){
		super(x,y,w,h);
		casino = n;
		cards = c;
		owner = o;
	}
	
	public void setOwner(Player p){
		owner = p;
	}
	
	public void removeOwner(){
		owner = null;
	}
	
	public boolean accesibleBy(Player p){
		if(p.equals(owner)){
			return true;
		}
		return false;
	}
	
	public void add(GameCard c){
		if(c != null){
			cards.add(c);
			c.setParent(this);
			lengthChange();
		}
	}
	
	public String toString(){
		String retVal = "";
		for(int i = 0; i < cards.size(); i++){
			retVal += cards.get(i).value+" of "+cards.get(i).suit+",\n";
		}
		return retVal;
	}
	
	public void remove(GameCard c){
		cards.remove(c);
		lengthChange();
	}
	
	public abstract void lengthChange();
}
